﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using CharacterTrailClient.Binding;
using CharacterTrailLibrary.Exceptions;
using CharacterTrailLibrary.Persist.BLL.Model;
using DevExpress.XtraEditors;

namespace CharacterTrailClient.Query.Item
{
    public partial class ProductItem : DevExpress.XtraEditors.XtraUserControl, IQueryItem
    {
        public ProductItem()
        {
            InitializeComponent();
// ReSharper disable DoNotCallOverridableMethodsInConstructor
            if (GlobalClass.RunTimeMode)
            {
                DataBindingStaticData();
            }
// ReSharper restore DoNotCallOverridableMethodsInConstructor
        }

        protected virtual void DataBindingStaticData()
        {
            DataBinder.BindingBomMainItem(this.gridLookUpEditProductItemNumber,null,this.textEditProductItemName,null);
            var dataSource = (List<TBomMainModel>)gridLookUpEditProductItemNumber.Properties.DataSource;
            var obj = new TBomMainModel();
            dataSource.Insert(0,obj);
        }

        public string Field { get; set; }

        public string GetCondition()
        {
            string condition = " and 1=1 ";

            if (String.IsNullOrEmpty(Field))
                throw new AppException("字段属性没有设置！");

            if (this.gridLookUpEditProductItemNumber.EditValue != null && !String.IsNullOrEmpty(this.gridLookUpEditProductItemNumber.Text.Trim()))
            {
                condition += (String.Format(" and {0}  = '{1}'", Field, gridLookUpEditProductItemNumber.Text.Trim()));
            }

            return condition;
        }

        public string Label
        {
            get
            {
                return this.labelControlMain.Text;
            }
            set
            {
                this.labelControlMain.Text = value;
            }
        }
    }
}
